package GUI;

import javax.swing.table.*;

import java.util.ArrayList;

import model.*;
import control.*;

public class casesTable extends DefaultTableModel
{
	private ArrayList<Case> cases = new ArrayList<Case>();
	private String user = "";
	private PersonCtrl personCtrl = new PersonCtrl();
	
	public casesTable()
	{
		
	}
	
	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}
	
	public void setCase(ArrayList<Case> _cases)
	{
		cases = _cases;
		fireTableDataChanged();
	}
	
	public ArrayList<Case> getC()
	{
		return cases;
	}
	
	@Override
    public int getColumnCount()
	{
        return 8;
	}
	
	@Override
	public int getRowCount()
	{
		if(cases == null)
		{
			return 0;
		}
		else
		{
			return cases.size();
		}
	}
	
	@Override
    public String getColumnName(int column)
	{
        String columnName = "";
        switch (column)
        {
        	case 0:
        		columnName = "ID";
        		break;
            case 1:
                columnName = "Start Date";
                break;
            case 2:
                columnName = "License Plate";
                break;
            case 3:
                columnName = "Client CVR";
                break;
            case 4:
                columnName = "Debtor CPR";
                break;
            case 5:
            	columnName = "Progress";
            	break;
            case 6:
                columnName = "End Date";
                break;
            case 7:
            	columnName = "Work";
            	break;
        }
        return columnName;
    }
	
	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch (column)
		{
		case 0:
			value = cases.get(row).getId();
			break;
		case 1:
			value = cases.get(row).getStartDate();
			break;
		case 2:
			value = cases.get(row).getVehicle().getLicensePlate();
			break;
		case 3:
			value = cases.get(row).getClient().getCvr();
			break;
		case 4:
			value = cases.get(row).getDebtor().getCpr();
			break;
		case 5:
			value = cases.get(row).getProcessed();
			break;
		case 6:
			if(!cases.get(row).getEndDate().equals("null"))
			value = cases.get(row).getEndDate();
			break;
		case 7:
			if(personCtrl.ifAssignedToCase(user, cases.get(row).getId()))
				value = "Assigned";
			else
				value = "NOT";
			break;
		}
		return value;
	}
	
	public void setUser(String _user)
	{
		user = _user;
	}
}
